package org.csu.goodpartner.persistence;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import org.apache.ibatis.annotations.Select;
import org.csu.goodpartner.VO.ItemVO;
import org.csu.goodpartner.entity.Item;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ItemMapper extends BaseMapper<Item> {
    @Select("select item.*, inventory.quantity from item, inventory " +
            "where item.itemid = inventory.itemid and item.shopid = inventory.shopid " +
            "and item.shopid=#{shopId}")
    List<ItemVO> getAllItems(int shopId);

    @Select("select item.* , inventory.quantity from item, inventory " +
            "where item.itemid = inventory.itemid and " +
            "item.shopid = inventory.shopid and item.shopid=#{shopId}" +
            "and (itemid.toString() like ? or name like ? or listprice.toString() like ?" +
            " or inventory.quantity.toString() like ? or classone like ? or classtwo like ?)")
    List<ItemVO> like(int shopId, String like);

//    @Select(
//            "select * from 表名 where  concat(\n" +
//            "     字段1\n" +
//            "    ,字段2\n" +
//            "    ,字段3\n" +
//            "    ) like 查询字符串")

    @Select("select item.* , inventory.quantity from item, inventory where item.itemid = inventory.itemid and item.shopid = inventory.shopid and " +
            "concat(item.itemid,category,name,description,classone,classtwo,listprice,quantity) like '%${s}%' and item.shopid=#{shopid}")
    List<ItemVO> searchAll(String s,int shopid);
}
